﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(ObjectPool))]
public class HeroController : PlayerController
{
    [Header("装备的枪械")]
    public Firearms p_Firearm;
    Firearms p_DefaultFirearm;
    [Header("装备的手雷")]
    public Bomb_Head p_Bomb;

    ObjectPool[] objectPools;
    float limitValue = 0.3f;
    int fireIndex = 0;
    AnimatorStateInfo playerCurrentStateInfo;//当前玩家的动画状态信息
    private void OnEnable()
    {
        p_DefaultFirearm = Resources.Load<Firearms>("Pistol");
        p_Firearm = p_DefaultFirearm;
        OnReSet();
    }
    void Start()
    {
        Init();
        objectPools = GetComponents<ObjectPool>();
    }
    private void FixedUpdate()
    {
        p_Firearm.Timer();//计时器（枪）
        OnFixedUpdate();
    }

    protected override void PlayerMove()//移动
    {
        if(Xaddition > limitValue || Xaddition < limitValue)
        {
            playerAnim.SetBool("IsMove", (Xaddition != 0));
        }
        if (Xaddition > 0)
        {
            transform.rotation = Quaternion.AngleAxis(0, transform.up);//正前
        }
        else if (Xaddition < 0)
        {
            transform.rotation = Quaternion.AngleAxis(180, transform.up);//后方
        }
    }
    protected override void PlayerJump()//跳跃
    {
        base.PlayerJump();
        playerAnim.SetBool("IsJump",isJump);
    }
    protected override void PlayerFire()//开火
    {
        p_Firearm.InstantiateBullet(fireTrans[fireIndex], Quaternion.identity, objectPools[0]);
    }
    protected override void PlayerThrow()//投掷
    {
    }

    private void PlayerYZhou(){
        if(Yaddition > 0) //向上
        {
            fireIndex = 1;
        }else if(Yaddition < 0)//向下
        {
            fireIndex = 2;
        }else if(Yaddition > 0 && Xaddition != 0)//斜角
        {
            fireIndex = 3;
        }else
        {
            fireIndex = 0;
        }
    }
}
